import React, { useState, useEffect } from "react";
const App = () => {
  const [count, setCount] = useState(1);
  const scorll = function () {
    window.onscroll = () => {
      console.log(count);
    };
  };

  useEffect(() => {
    //这是一个一次性的钩子函数,里面的值是定值,里面的值不会改变
    scorll();
    console.log("挂载");
  }, []);
  useEffect(() => {
    console.log("更新");
    scorll();
  }, [count]);
  const setState = () => {
    setCount(count + 1);
  };

  return (
    <div style={{ height: "5000px" }}>
      <button style={{ position: "fixed" }} onClick={setState}>
        ++
      </button>
    </div>
  );
};
export default App;
